package com.shop.shoppingmall.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shop.shoppingmall.entity.ShBanner;
import com.shop.shoppingmall.entity.ShProportion;
import com.shop.shoppingmall.service.ShProportionService;
import com.shop.shoppingmall.util.api.vo.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 比例(ShProportion)表控制层
 *
 * @author makejava
 * @since 2020-09-11 08:58:06
 */
@RestController
@RequestMapping("shProportion")
@CrossOrigin
public class ShProportionController {
    /**
     * 服务对象
     */
    @Resource
    private ShProportionService shProportionService;

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @PostMapping("selectOne")
    public Result selectOne(@RequestBody Map map) {
      String id =  map.get("id").toString();
        System.out.println(id);
        return shProportionService.queryById(id);
    }

    /**
     * 添加比例
     * @param jsonObject
     * @return
     */
    @PostMapping("insertProportion")
    public Result insertProportion(@RequestBody JSONObject jsonObject) {
        ShProportion shProportion = JSON.parseObject(jsonObject.toJSONString(), ShProportion.class);
        return shProportionService.insert(shProportion);
    }

    /**
     * 修改比例
     * @param jsonObject
     * @return
     */
    @PostMapping("updateProportion")
    public Result updateProportion(@RequestBody JSONObject jsonObject) {
        ShProportion shProportion = JSON.parseObject(jsonObject.toJSONString(), ShProportion.class);
        return shProportionService.update(shProportion);
    }

    @GetMapping("queryAll")
    public Result queryAll() {
        return shProportionService.queryAll();
    }

}
